package com.zer0.tga.entity.abstractentity;

import com.zer0.tga.art.Bitmap;
import com.zer0.tga.art.Screen;
import com.zer0.tga.entity.Entity;
import com.zer0.tga.math.Coordinate;

public class Blinker extends AbstractEntity{

	private int color;
	private int blinkingTime;
	private int cooldownTime;
	private int maxCount;
	
	private int count = 0;
	private int timer = 0;

	public boolean shouldDraw = false;
	
	public Blinker(Coordinate pos, Coordinate rad)
	{
		this.setPositionAndRadius(pos, rad);
	}
	
	public Blinker(Coordinate pos, Coordinate rad, int color, int blinkingTime, int cooldownTime, int maxCount)
	{
		this.setPositionAndRadius(pos, rad);
		this.color = color;
		this.blinkingTime = blinkingTime;
		this.cooldownTime = cooldownTime;
		this.maxCount = maxCount;
	}
	
	public void tick()
	{
		if(count < maxCount)
		{

			timer++;
			
			if(timer >= blinkingTime+cooldownTime)
			{
				count++;
				timer = 0;
				//if(cooldownTime > 4)
					cooldownTime--;
					blinkingTime--;
			}
			else if(timer <= blinkingTime)
			{
				shouldDraw = true;
			}
			else
				shouldDraw = false;
		}
		else
			this.removed = true;
	}

	public void render(Screen screen)
	{
		if(shouldDraw)
		{
			Bitmap b = new Bitmap((int)radius.x*2,(int)radius.y*2);
			b.clearWithColor(color);
			screen.draw(b,position.x-radius.x,position.y-radius.y,position.x+radius.x,position.y+radius.y);
		}
	}

	public boolean blocks(Entity e) {

		return false;
	}	
	public AbstractEntity changeToDamager(int damage)
	{
		return new Damager(position, radius, damage, 2);
	}
	
}
